/**
 * 
 */
package org.hospital.action;

import org.hospital.dao.IPatientDAO;
import org.hospital.dao.IUserDAO;
import org.hospital.pojo.TFirVisit;
import org.hospital.pojo.TPatient;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author HuangKai
 *
 */
public class AddFirstAction {
	private AbstractApplicationContext aac = new ClassPathXmlApplicationContext(
	"applicationContext.xml");
	
	private TPatient patient;

	public TPatient getPatient() {
		return patient;
	}

	public void setPatient(TPatient patient) {
		this.patient = patient;
	}
	
	private TFirVisit firVisit;
	
	
	public TFirVisit getFirVisit() {
//		if (patient!=null){
//			for (TFirVisit firVisit:patient.getFirVisit()){
//				this.firVisit= firVisit;
//				return this.firVisit;
//			}
//		}
		firVisit.setComplaint("aa");
		return firVisit;
	}

	public void setFirVisit(TFirVisit firVisit) {
		this.firVisit = firVisit;
	}

	public String execute() throws Exception {
		if (patient.getFirVisit().isEmpty()){
			patient.addFirVisit(firVisit);
		}
		IPatientDAO patientDao = (IPatientDAO) aac.getBean("PatientDAO");
		patientDao.attachDirty(patient);
		
		return "success";
	}
	
}
